<link rel="stylesheet" href="components/com_kinh_doanh/assets/jquery-ui.css"/>
<link rel="stylesheet" href="components/com_kinh_doanh/assets/style2.css"/>
<script language="javascript" src="components/com_kinh_doanh/assets/jquery-1.8.2.js"></script>
<script language="javascript" src="components/com_kinh_doanh/assets/jquery-ui.js"></script>
<script type="text/javascript">
function kiem_tra(val,sl,id)
{

    var x = typeof val; 

   if(sl<val)
   {
    alert("so luong khong du.");
    document.getElementById(id).value = 0;
   }
}
function add(id)
{ 
    
    var x = eval(document.getElementById('sp'+id).value);
    x+=1;
    document.getElementById('sp'+id).value = x;
    return;
}
function sub(id)
{
    if(eval(document.getElementById('sp'+id)).value==0)
    {
        alert("Số lượng không được bé hơn 0."); return;
    }
    else
    {
        var x = eval(document.getElementById('sp'+id).value);
        x-=1;
        document.getElementById('sp'+id).value = x;
        return;
    }
}
</script>

<?php 
	jimport('joomla.application.component.view');
	//thuc hien goi  model phu hop
	class sale_tsc_orderVieworder_sp extends JView
	{
		function display($tpl=null)
		{
		  
            $model = $this->getModel();
            $data=$model->danh_sach_san_pham();
            ?>
                <form action="index.php?option=com_sale_tsc_order&task=order_them_dh" name="frm1" id="frm1" method="post">
<?php
    $type = "";
    //echo count($data);die;

    for($i=0;$i<count($data);$i++)
    {
        if($type != $data[$i]->name_type)
        {
            $type = $data[$i]->name_type;
            echo $type;  
            echo "<br />"?>
            
            <?php  
        }
        if($type == $data[$i]->name_type)
        {
            ?>
                <div class="product_box" style="width: 200px; padding-left: 15px;padding-bottom: 1px;float:left;">
            <img src="components/com_adminshop/assets/images/upload/thumb/<?php $img = explode(",", $data[$i]->img); echo $img[0];?>" width="150" height="80" /> 
                    <br /><?php echo $data[$i]->name;?>
                    <br/>Giá:<?php echo $data[$i]->price;?></strong><br />Số lượng: <span id="sl"><?php echo $data[$i]->number_of; ?></span>
                        
                        <br/><table>
                            <tr>
                                <td>
                                <input <?php if($data[$i]->number_of <= 0)
                                    echo 'disabled="disabled"';?>
                                type="button" class="button1" value="Thêm" onclick="return add(<?php echo $data[$i]->id_pro; ?>)" />
   
                                </td>
                                <td>
                                <input <?php if($data[$i]->number_of <= 0)
                                    echo 'disabled="disabled"';?> type="button" class="button1" onclick="return sub(<?php echo $data[$i]->id_pro; ?>)" value="Bớt" />
            
                                </td>
                            </tr>
                        </table>
                        <input <?php if($data[$i]->number_of <= 0)
                                    echo 'disabled="disabled"';?> type="text" id="sp<?php echo $data[$i]->id_pro; ?>" name="sp<?php echo $data[$i]->id_pro; ?>" value="0" onchange="return kiem_tra(this.value,<?php echo $data[$i]->number_of;?>,'sp<?php echo $data[$i]->id_pro;?>')" />
                    </div>
            <?php
        }
 
                    if($i<count($data)-1)
                    {
                        if($data[$i+1]->name_type != $type)
                            {
                                echo "<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>";
                                
                            }
                    }
                    if($i==count($data)-1)
                    {
                                echo "<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>";
                                
                            }
              
        
   }?>


<input type="submit" name="btnnext" value="Tiếp Tục" />
</form>
            <?php
		}	
	}
?>